﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using AbpBuild.Configuration;
using AbpBuild.Web;

namespace AbpBuild.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class AbpBuildDbContextFactory : IDesignTimeDbContextFactory<AbpBuildDbContext>
    {
        public AbpBuildDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<AbpBuildDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            AbpBuildDbContextConfigurer.Configure(builder, configuration.GetConnectionString(AbpBuildConsts.ConnectionStringName));

            return new AbpBuildDbContext(builder.Options);
        }
    }
}
